import api from '@/api';

export default {
  namespace: 'financialAfterSale',
  state: {
    compensationList: {
      list: [],
      pagination: {},
    }
  },

  effects: {
    *fetchCompensationList({ payload }, { call, put }) {
      const response = yield call(api.financialAfterSale.compensationList, payload);
      if (response.errorCode === 0) {
        yield put({
            type: 'saveCompensationList',
            payload: {
              list: response.data,
              pagination: response.pagination,
            },
        });
      }
      return response
    },
    *payAccount({ payload }, { call, put }) {
      return yield call(api.financialAfterSale.payAccount, payload);
    },
    *payOffline({ payload }, { call, put }) {
      return yield call(api.financialAfterSale.payOffline, payload);
		},
		*cancelPayAccount({ payload }, { call, put }) {
      return yield call(api.financialAfterSale.cancelPayAccount, payload);
    },
    *cancelPayOffline({ payload }, { call, put }) {
      return yield call(api.financialAfterSale.cancelPayOffline, payload);
    },
    *receiveMoney({ payload }, { call, put }) {
      return yield call(api.financialAfterSale.receiveMoney, payload);
    },
  },

  reducers: {
    saveCompensationList(state, { payload }) {
        return {
          ...state,
          compensationList: payload,
        };
      },
  },
};
